package com.jt.controller;

import com.jt.entity.MeterageDict;
import com.jt.entity.MeterageTemperamentReportChildren;
import com.jt.entity.Meterage_ReportChildren;
import com.jt.pojo.*;
import com.jt.service.UserService;
import com.jt.utils.JwtUtil;
import com.jt.vo.RoleVo;
import com.jt.vo.MenuAndRolesVo;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xwpf.usermodel.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.ClassPathResource;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.FileInputStream;
import java.io.OutputStream;
import java.util.*;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    public UserService userService;
    @Autowired
    public JwtUtil jwtUtil;

    /*登录用户*/
    @PostMapping("/login")
    public Result login(@RequestBody User user) {
        User userResult = userService.login(user);
        if (Objects.isNull(userResult)) {
            return Result.error("对象为null");
        }
        String token = jwtUtil.getToken(userResult.getId());
        return Result.success(token);
    }

    /*获取权限路由菜单*/
    @GetMapping("/info")
    public Result getInfo(String token) {
        return userService.getInfo(token);
    }

    @GetMapping("/exportWps1")
    public void exportWps1(String id, HttpServletResponse response) throws Exception {
        userService.exportWps1(id, response);
    }

    @GetMapping("/export")
    public void exportWps(HttpServletResponse response) throws Exception {
        userService.exportWps(response);
    }

}


